
function sayHello(name, age) {
  console.log(`hello, my name is ${name}, I am ${age} years old`);
}
/*  apply 立即执行函数，参数以数组格式传递  */
// sayHello.apply(null, ['小红', 18])

/* call。立即执行函数，参数用逗号隔开 */
// sayHello.call(this, '小红', 18)

/* bind 非立即执行函数，参数以数组格式传递  */
// const greetBind = sayHello.bind(this, ['小红', 18])
// greetBind()


/* 自定义实现bind */
Function.prototype.myBind = function (thisArg, ...boundArgs) {
  const originfFunc = this; //谁调用 this指向谁
  return function (...args) {
    return originfFunc.apply(thisArg, [...boundArgs, ...args])
  }
}

const greetBound = sayHello.myBind(null, "麦克");
greetBound(15); // Hello, Charlie! You are 40 years old.